package com.sram.dao.impl;
import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.net.SyslogAppender;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.HibernateTemplate;
import com.sram.dao.PhotoDao;
import com.sram.entity.Photo;
public class PhotoDaoImpl implements PhotoDao {
	private HibernateTemplate template;
	public HibernateTemplate getTemplate() {
		return template;
	}
	public void setTemplate(HibernateTemplate template) {
		this.template = template;
	}
	@Override
	public void addPhoto(Photo photo) {
		template.save(photo);
	}
	@Override
	public List<Photo> findPhoto(DetachedCriteria detachedCriteria) {
		return template.findByCriteria(detachedCriteria);
	}
	
	@Override
	public void deletePhoto(int id) {
		Photo photo = (Photo) template.get(Photo.class, id);
		template.delete(photo);
	}
	@Override
	public void updatePhoto(Photo photo) {
		template.update(photo);
	}
	@Override
	public List<Photo> pageQuery(DetachedCriteria detachedCriteria, int firstResult, int pageSize) {
		// TODO Auto-generated method stub
		return this.getTemplate().findByCriteria(detachedCriteria, firstResult, pageSize);
	}
}
